package kr.saeildadim.androidexam_saeildamil.chapter16;

import java.text.BreakIterator;

import kr.saeildadim.androidexam_saeildamil.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Ch16_Order extends Activity {
	LinearLayout layout;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch16_ordermain);
		
	}
	public void mOnClick(View v){
		LinearLayout layout = (LinearLayout) View.inflate(this, R.layout.ch16_order, null);
		new AlertDialog.Builder(this)
		.setTitle("주문 정보를 입력하세요")
		.setIcon(R.drawable.ic_launcher)
		.setView(layout)
		.setPositiveButton("확인", listener)
		.show();
	}
	DialogInterface.OnClickListener listener = new OnClickListener() {
		
		@Override
		public void onClick(DialogInterface dialog, int which) {
			TextView result = (TextView) findViewById(R.id.ch16_order_main_tv1);
			switch (which){
			case DialogInterface.BUTTON_POSITIVE:
				EditText product =(EditText) layout.findViewById(R.id.ch16_order_ed1);
				EditText number = (EditText) findViewById(R.id.ch16_order_ed2);
				CheckBox paymethod = (CheckBox) layout.findViewById(R.id.ch16_order_chbox);
				result.setText("주문 정보"+product.getText()+"상품 :"+number.getText()+"개"+(paymethod.isChecked()?"착불결제":""));
				break;
			case DialogInterface.BUTTON_NEGATIVE:
				TextView text = (TextView) findViewById(R.id.ch16_order_main_tv1);
				text.setText("주문을 취소하였습니다");
				break;
			}
			
		}
	}; 
}
